package org.example.controller;

import com.alibaba.fastjson2.JSON;
import org.example.rvo.ResultVO;
import org.example.util.JSONUtil;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

@RestController
public class RestEntityController {

    @Resource
    private RestTemplate restTemplate;

    private final String url = "https://api.vvhan.com/api/horoscope?time=today";

    @GetMapping(value = "/horoscope",produces = "application/json;charset=UTF-8")
    public ResultVO horoscope(@RequestParam("type") String type) throws Exception{
        Map<String, String> map = new HashMap<>();
        map.put("type", type);
        String forObject = restTemplate.getForObject(url + "&type=" + type, String.class);
        System.out.println(forObject);
        return JSON.parseObject(forObject,ResultVO.class);
    }
}
